﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EzDesk.Core.Model;

namespace EzDesk.Core.Interface
{
    public interface ICoreService
    {
        #region [System Globle Info - lastReview: 2011.1.5]
        Organization GetOrganizationInfo();
        #endregion

        #region [ Users Profile Methods - lastReview: 2010.3.3]
        UserProfile GetUserProfileByUserName(string userName);
        UserProfile GetUserProfileById(Guid userId);
        IList<UserProfile> GetUserProfiles(Guid[] userIdCollection);
        IList<UserProfile> GetUserProfiles(string memberstring);
        void UpdateUserProfile(UserProfile userProfile);

        void ChangeUserDept(Guid userId, Guid deptId);
        void ChangeUserPosition(Guid userId, Guid positionId);

        UserProfile CreateEmptyUserProfile(string userName);
        void DeleteUserProfile(Guid userId);

        IList<SimpleUser> GetSimpleUserInfos(Guid[] userIdCollection);
        IList<SimpleUser> GetSimpleUserInfos(string memberstring);
        SimpleUser GetSimpleUserById(Guid userId);

        SimpleUser GetSimpleUserInfoByUserName(string userName);
        IList<SimpleUser> GetUsersInDept(Guid deptId);
        IList<SimpleUser> GetUsersInPosition(Guid posId);

        void UpdateHeadIcon(Guid userId, byte[] iconData, string imageType);
        UserHeadImage GetHeadIcon(Guid userId);

        #endregion [ Users Profile Methods - lastReview: 2010.3.3]

        #region [ Department    -   2010.1.17]
        IList<Dept> GetAllDepts();
        Dept GetDeptById(Guid deptId);
        Dept CreateDept(string deptName);
        void RemoveUserFromCurrentDept(Guid userId);
        void ChangeDeptName(Guid deptId,string deptName);
        void DeleteDept(Guid deptId);
        #endregion [ Department    -   2010.1.17]

        #region [ Group & Memberstring    -   2010.10.28]
        Group CreateGroup(SimpleUser[] userIds,Group[] groupIds,string descrition,int type);
        void DeleteGroup(Guid groupId);
        void ChangeGroupDescription(Guid groupId, string description);

        IList<Group> GetAllSystemGroups();
        Group GetSystemGroup(string sysGroupName);

        Group GetGroupByName(string groupName);
        Group GetGroupById(Guid groupId);
        IList<Group> GetGroups(string groupIdStrs);
        IList<Group> GetGroups(Guid[] groupIdCollection);

        IDictionary<Guid, string> GetChildrenByMemberstring(string memberString);

        IList<SimpleUser> GetAllUsersInGroup(Guid groupId);

        IList<Group> GetUserInGroups(Guid userId, int groupType = -1 /* 指明用户组类型，<0则不判断  */);
        bool IsUserInGroup(Guid userId, Guid groupId);

        IList<Guid> GetAllUserIdsByMemberString(string memberString);
        IList<SimpleUser> GetAllUsersByMemberString(string memberString);

        void AddUserInGroup(Guid targetGroupId, Guid userId);
        void AddGroupInGroup(Guid targetGroupId, Guid groupId);
        void RemoveUserFromGroup(Guid targetGroupId, Guid userId);
        void RemoveGroupFromGroup(Guid targetGroupId, Guid groupId);

        #endregion [ Group    -   2010.10.28]

        #region [ Position    -   2010.1.17]
        IList<Position> GetPositions();
        Position CreatePosition(string descrition, int priority);
        void ChangePositionPriority(Guid posId,int priority);
        void ChangePositionDescription(Guid posId, string description);
        void DeletePosition(Guid positionId);
        #endregion [ Position    -   2010.1.17]

        #region [ Feed Common    -   2010.3.3 ]

        void UpdateFeedStatus(IList<FeedStatus> feedStatus, string memeberString);

        void DeleteFeed(Guid feedId, int type);
        void UpdateFeedData(Guid feedId, string newFeedData);
        void UpdateFeedData(string feedIdStrs, string newFeedData);

        IList<Feed> GetFeeds(string feedTypeStr, Guid userId, DateTime from, DateTime to, int maxCount, bool? isRead, bool? isAvaiable, bool? isMark);
        IList<Feed> GetFeeds(string feedTypeStr, Guid userId, int startIndex, int count, bool? isRead, bool? isAvaiable, bool? isMark);

        // 使用templateName发送Feed
        Guid SendFeed(
            string templateName, /* 使用的模板名称 */
            string feedData, /* Feed数据 */
            string memberString, /* 接收者 */
            DateTime expireOn,   /* 过期时间 */
            Guid? senderId, /* 发送者UserID 可空 */
            string ignoreUsers, /* 这条消息忽略发射的人 */ 
            bool isAvailable    /* 该feed是否有效 */
            );

        void UpdatePersonalFeedData(Guid feedId, string memberstring, string feedDataEx);
        void UpdatePersonalFeedType(Guid feedId, string memberstring, string feedTypeStr);

        string GetPersonalFeedData(Guid userId, Guid feedId);

        // 设置Feed发送记录
        void SetFeedRecord(Guid identity, string templateName, string memberstring, Guid feedId, string ignoreUsers);
        // 获取Feed发送记录
        string GetFeedRecord(Guid identity, string templateName, string userId);
        #endregion

        #region [ FeedTemplate    -   2010.3.17]
        FeedTemplate CreateFeedTemplate(string titleTemplate,string bodyTemplate,int type);
        void DeleteFeedTemplate(Guid templateId);
        FeedTemplate GetFeedTemplateById(Guid templateId);
        IList<FeedTemplate> GetFeedTemplate(string templateName);
        #endregion [ FeedTemplate    -   2010.1.17]

        #region [ Permission   -  2010.9.17 ]
        /// <summary>
        /// 在系统中注册一个权限
        /// </summary>
        /// <param name="permission"></param>
        void RegisterPermission(Permission permission);

        /// <summary>
        /// 根据AppId获得权限列表
        /// </summary>
        /// <param name="AppId">权限列表的AppName，为空则获得Core权限</param>
        /// <returns></returns>
        IList<Permission> GetPermissionList();

        /// <summary>
        /// 根据一个 用户权限字符串 获得一个权限
        /// </summary>
        /// <param name="permissionStr"></param>
        /// <returns></returns>
        Permission GetPermission(string permissionStr);

        /// <summary>
        /// 设置某个用户组的权限
        /// </summary>
        /// <param name="permissionStr">用户权限字符串</param>
        /// <param name="userId"></param>
        /// <param name="hasPermission"></param>
        void SetGroupPermission(string permissionStr, Guid groupId, bool hasPermission);

        /// <summary>
        /// 用户是否拥有权限
        /// </summary>
        /// <param name="permissionStr">用户权限字符串</param>
        /// <param name="userId">用户Id</param>
        /// <returns></returns>
        bool UserHasPermission(string permissionStr, Guid userId);


        /// <summary>
        /// 用户组是否拥有权限
        /// </summary>
        /// <param name="permissionStr">用户权限字符串</param>
        /// <param name="userId">用户组Id</param>
        /// <returns></returns>
        bool GroupHasPermission(string permissionStr, Guid groupId);


        #endregion

    }
}
